﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Data;

namespace TfsBacklogMgr.Main
{
    public class SprintWorkItemTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            if (element != null && item != null && item is Iteration )
            {
                Iteration iter = item as Iteration;
                object o = element.FindResource("SprintIterationTemplate");
                HierarchicalDataTemplate h = o as HierarchicalDataTemplate;
                return h;
            }
            if (element != null && item != null && item is WorkItem )
            {
                WorkItem workitem = item as WorkItem;
                HierarchicalDataTemplate h = null;
                if (string.Compare(workitem.WIT, Context.GetContext().WIT_Story, true) == 0)
                    h = element.FindResource("WorkItemUserStoryTemplate") as HierarchicalDataTemplate;
                else
                    if (string.Compare(workitem.WIT, Context.GetContext().WIT_Bug, true) == 0)
                        h = element.FindResource("WorkItemBugTemplate") as HierarchicalDataTemplate;
                else
                    h = element.FindResource("WorkItemTaskTemplate") as HierarchicalDataTemplate;
                return h;
            }

            return null;
        }
    }

    public class BacklogtWorkItemTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            if (element != null && item != null && item is Iteration)
            {
                Iteration iter = item as Iteration;
                object o = element.FindResource("BacklogIterationTemplate");
                HierarchicalDataTemplate h = o as HierarchicalDataTemplate;
                return h;
            }
            if (element != null && item != null && item is WorkItem)
            {
                WorkItem workitem = item as WorkItem;
                HierarchicalDataTemplate h = null;
                if ( string.Compare(workitem.WIT, Context.GetContext().WIT_Story, true ) == 0)
                    h = element.FindResource("WorkItemUserStoryTemplate") as HierarchicalDataTemplate;
                else
                if ( string.Compare(workitem.WIT, Context.GetContext().WIT_Bug, true ) == 0 )
                    h = element.FindResource("WorkItemBugTemplate") as HierarchicalDataTemplate;
                else
                    h = element.FindResource("WorkItemTaskTemplate") as HierarchicalDataTemplate;
                return h;
            }

            return null;
        }
    }

}
